package week6;

import java.math.BigInteger;

public class Ex55 {
    public static boolean isPalindrome(String s){
        StringBuilder sb = new StringBuilder(s).reverse();
        return sb.toString().equals(s);
    }
    public static BigInteger BigPalindrome(BigInteger b){
        StringBuilder sb = new StringBuilder(b.toString()).reverse();
        return new BigInteger(sb.toString());
    }

    public static void main(String[] args) {
        int ans = 0;
        BigInteger a;
        boolean flag;
        int c;
        for (int i = 11; i <= 10000; ++i){
            flag = true;
            c = 50;
            a = BigInteger.valueOf(i);
            while (c > 0){
                a = a.add(BigPalindrome(a));
                if (isPalindrome(a.toString())){
                    flag = false;
                    break;
                }
                c--;
            }
            if (flag)
                ans++;
        }
        System.out.println(ans);
    }
}
